package org.vnl.platform.web.impl.myfaces.dojo.component.tag;

import javax.el.ValueExpression;
import javax.faces.component.UIComponent;

import org.apache.commons.lang3.StringUtils;
import org.vnl.platform.web.impl.myfaces.dojo.component.DojoTextBox;


abstract public class AbstractDojoTextBoxTag extends DojoTag {

    private ValueExpression value;
    
    public ValueExpression getValue() {
        return value;
    }

    public void setValue(ValueExpression value) {
        this.value = value;
    }
    
    protected void setValueProperty(DojoTextBox box) {
        if (value != null) {
            box.setValueExpression("value", value);
        }
    }
    
    @Override
    protected void setProperties(UIComponent arg0) {
        super.setProperties(arg0);
        if (arg0 instanceof DojoTextBox) {
            DojoTextBox box = (DojoTextBox) arg0;
            String tmp = getDojoIdValue();
            if (!StringUtils.isBlank(tmp)) {
                box.setDojoId(tmp);
            }
            tmp = getDojoPropsValue();
            if (!StringUtils.isBlank(tmp)) {
                box.setDojoProps(tmp);
            }
            setValueProperty(box);
        }
    }
}
